<template>
	<!-- 维保管理/保养计划 -->
	<div class="heightMax order publicbox planBox" v-loading='loading'>
		<div class="header">
			<el-row :gutter="10">
				<el-col :span="4">
					<el-input size="mini" @keyup.enter.native="find" placeholder="请按照关键词查找" clearable v-model="query"></el-input>
				</el-col>
				<el-col :span="4">
					<el-select size="mini" placeholder="完成状态" clearable v-model="status">
						<el-option v-for="item in condition" :value="item.value" :key="item.value" :label="item.label"></el-option>
					</el-select>
				</el-col>
				<el-col :span="4">
					<el-date-picker size="mini" v-model="time_from" type="date" placeholder="选择开始日期" format='yyyy-MM-dd' value-format='yyyy-MM-dd'
					 @change='changeTime'>
					</el-date-picker>
				</el-col>
				<el-col :span="4">
					<el-date-picker size="mini" v-model="time_to" type="date" placeholder="选择结束日期" format='yyyy-MM-dd' value-format='yyyy-MM-dd'
					 :picker-options="pickerOptions" :disabled="timeDisabled">
					</el-date-picker>
				</el-col>
				<el-col :span="1.5">
					<div v-if="showVis">
						<el-popover placement="bottom" width="400" v-model="showProp" trigger="manual">
							<el-row :gutter="10" class='currentRow1'>
								<el-col :offset='1'>
									<el-select size="mini" placeholder="时间状态" clearable v-model="timeStatus">
										<el-option v-for="item in timeStatusArr" :value="item.value" :key="item.value" :label="item.label"></el-option>
									</el-select>
								</el-col>
							</el-row>
							<el-row :gutter="10" class='currentRow1'>
								<el-col :offset='1'>
									<el-select size="mini" placeholder="关注" clearable v-model="attentionStatus">
										<el-option v-for="item in attentionStatusArr" :value="item.value" :key="item.value" :label="item.label"></el-option>
									</el-select>
								</el-col>
							</el-row>
							<div class="btnBox">
								<el-button type="primary" size="mini" @click="find">确定</el-button>
								<el-button size="mini" @click="closeVis">关闭</el-button>
							</div>
						</el-popover>
					</div>
					<el-button :type="btnType" class='btnMargin' @click='showVis = true' size="mini">更多查询条件</el-button>
				</el-col>
				<el-col :span="1.5">
					<el-button type="primary" icon="el-icon-search" @click='find' size="mini">搜索</el-button>
				</el-col>
				<el-col :span="1.5">
					<el-button icon="el-icon-delete" @click='reset' size="mini">重置</el-button>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-col :span="1.5">
					<!-- v-if="role != 0" -->
					<el-button type="primary" :disabled="complieBtn" @click='compileFn' v-if="complieBtnShow" size="mini">编辑</el-button>
				</el-col>
				<!-- v-if="role != 0" -->
				<el-col :span="1.5">
					<el-button type="danger" :disabled="complieBtn " @click='deleteList(1)' v-if="deleteBtnShow" size="mini">删除</el-button>
				</el-col>
				<el-col :span="1.5">
					<el-button type="success" :disabled="detailBtn" @click='lookDetail' v-if="readDataShow" size="mini">详情</el-button>
				</el-col>
				<el-col :span="1.5" v-if="role == 0">
					<el-button type="primary" @click='jin' size="mini">今日故障工单</el-button>
				</el-col>
				<el-col :span="1.5" v-if="role == 0">
					<el-button type="primary" @click='zuo' size="mini">昨日故障工单</el-button>
				</el-col>
				<el-col :span="1.5" v-if="role == 0">
					<el-button type="primary" @click='other' size="mini">其他故障工单</el-button>
				</el-col>
				<el-col :span="1.5" v-if="readDataShow">
					<el-button type="primary" @click='operationFn' :disabled="operationBtn" size="mini">手动提交备案</el-button>
				</el-col>
				<el-col :span="1.5">
					<el-button type="danger" :disabled="batchDisable" @click='deleteList(2)' v-if="deleteBtnShow" size="mini">批量删除</el-button>
				</el-col>
				<!-- v-if="role != 0" -->
				<el-col :span="1.5" v-if="readDataShow">
					<el-button type="primary" @click='changeStatusBtn' size="mini">{{messageChange}}</el-button>
				</el-col>
				<!-- v-if="role != 0" -->
				<el-col :span="1.5" v-if="readDataShow">
					<el-button type="primary" :disabled="submitPact" @click='sumbShiJu' size="mini">工单提交市局</el-button>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-col :span="1.5" v-if="readDataShow">
					<el-button type="primary" :disabled="submitPact" @click='reBack' size="mini">打回调整</el-button>
				</el-col>
				<!-- v-if="danweiStatus && role != 0 && messageChange == '改为自动提交' && readDataShow" -->
				<el-col :span="2">
					<el-button type="primary" :disabled="shangChuanDis" @click="modification" size="mini">修改上传数据</el-button>
				</el-col>
				<el-button type="success" @click='addPlan' class='fr' v-if="addBtnShow" size="mini">添加</el-button>
				<!-- v-if="role != 0" -->
				<el-button type="primary" @click='educe' class='fr' v-if="readDataShow" size="mini">导出</el-button>
				<el-button type="primary" v-if="false" class='fr' @click="dialogVisible = true" size="mini">导入</el-button>
			</el-row>
		</div>
		<!-- 导入 -->
		<div class="goLeadBox">
			<el-dialog custom-class="intoDialog" :append-to-body='true' title="请上传模板文件" :visible.sync="dialogVisible" width="450px"
			 :close-on-click-modal="false">
				<div style="height:110px;z-index: 3333;" class="upModelBox">
					<el-upload action="" list-type="text" :file-list="fileList" :auto-upload="false" name="task">
						<el-button size="mini" type="primary">点击上传</el-button>
						<a href="http://www.africle.xyz:8088/uploaded/维保人员.xlsx" target="_blank">
							<div slot="tip" class="moban">点击下载模板</div>
						</a>
						<div slot="tip" style="margin-top: 20px;font-size: 14px;">只能上传一份XLSX文件</div>
					</el-upload>
				</div>
				<span slot="footer">
					<el-button @click="callOff">取消</el-button>
					<el-button type="primary" @click='submit' v-loading='upBtnLoading'>确定</el-button>
				</span>
			</el-dialog>
		</div>
		<!-- 表格 -->
		<div class="tableBox">
			<vueScroll>
				<el-table :data="tableData" highlight-current-row ref="moviesTable" @sort-change='sortChange' @row-click="rowClick"
				 @select-all="selectChange" @selection-change="selectChange" style="width: 100%" border header-row-class-name='tableHeader'>
					<el-table-column type="index" class="over" fixed>
					</el-table-column>
					<el-table-column type="selection" min-width="50" fixed>
					</el-table-column>
					<el-table-column label="工单状态">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.statusName" placement="top">
								<span class="speSpan">{{scope.row.statusName}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="工单编码" sortable='custom' property="sn">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.sn" placement="top">
								<span class="speSpan">{{scope.row.sn}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="计划日期" sortable='custom' property="day">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.day" placement="top">
								<span class="speSpan">{{scope.row.day}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="完成日期" sortable='custom' property="task_end_time">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.task_end_time" placement="top">
								<span class="speSpan">{{scope.row.task_end_time}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="注册代码" sortable='custom' property="register_code">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.register_code" placement="top">
								<span class="speSpan">{{scope.row.register_code}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="内部编号" sortable='custom' property="internal_no">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.internal_no" placement="top">
								<span class="speSpan">{{scope.row.internal_no}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="维保单位">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.maintain_company_name" placement="top">
								<span class="speSpan">{{scope.row.maintain_company_name}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="使用单位">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.property_company_name" placement="top">
								<span class="speSpan">{{scope.row.property_company_name}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="备注">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.desc" placement="top">
								<span class="speSpan">{{scope.row.desc}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
					<el-table-column label="最后更新人">
						<template slot-scope="scope">
							<el-tooltip class="item" effect="dark" :content="scope.row.update_by_name" placement="top">
								<span class="speSpan">{{scope.row.update_by_name}}</span>
							</el-tooltip>
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页器 -->
				<div class="pag">
					<el-pagination :current-page="page" :page-sizes="[10, 20, 30, 40]" :page-size="page_size" layout="total, sizes, prev, pager, next, jumper"
					 :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange">
					</el-pagination>
				</div>
			</vueScroll>
		</div>
		<transition name='el-fade-in'>
			<orderDetail v-if='detailShow' :detailShow='detailShow' :rowId='rowId' @maskShow="maskShowNow"></orderDetail>
			<changeShiJu v-if='shujuShow' :detailShow='shujuShow' :rowId='rowId' @maskShow="maskShowNow"></changeShiJu>
			<addAndCompile v-if='addAndCompileShow' :isAddOrComp='isAddOrComp' :addAndCompileShow='addAndCompileShow'
			 @detailMaskShow='detailMaskShow' :rowId='rowId'></addAndCompile>
		</transition>

		<el-dialog custom-class="changePeo" :visible.sync="showPerson" title="选择退回修改人员" :append-to-body='true' :before-close='ClosePersonAlet'>
			<el-radio-group v-model="radio">
				<el-radio :label="item.person_id" v-for="(item) in personArr" :key='item.person_id'>{{item.person_name}}</el-radio>
			</el-radio-group>
			<div slot="footer" class="dialog-footer">
				<el-button @click="ClosePersonAlet">取 消</el-button>
				<el-button type="primary" v-loading='ensureBtn' @click='ensureClick'>确 定</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		loadFn,
		axiosPost,
		axiosGet,
		axiosDelete,
		axiosPut,
		noLoadingPost,
		moment,
		axiosChange,
		AllLoading
	} from "@/common.js";
	import orderDetail from './orderDetail.vue'
	import addAndCompile from "./addAndCompile"
	import changeShiJu from "./changeShiJu"
	export default {
		activated() {
			if (!this.newFlag) {
				this.firstMethods()
			}
		},
		mounted() {
			this.firstMethods()
			this.getTableList()
			if (this.role != 0) {
				this.getStatus()
			}
			this.getPermition()
		},
		components: {
			orderDetail,
			addAndCompile,
			changeShiJu
		},
		data() {
			return {
				btnType:'primary',
				showVis: false,
				attentionStatus: '',
				attentionStatusArr: [{label:'我的关注',value:1},{label:'其他',value:0},{
					value:2,
					label:'全部',
				}],
				showProp: true,
				total: 10,
				page: 1,
				page_size: 10,
				query: '',
				status: '',
				time_from: '',
				time_to: '',
				order_by: '-day',
				loading: true,
				tableData: [],
				fileList: [],
				dialogVisible: false,
				disableBtn: true,
				batchDisable: true,
				//弹窗
				detailShow: false,
				addAndCompileShow: false,
				isAddOrComp: 1,
				deleteArr: [],
				complieBtn: true,
				detailBtn: true,
				rowId: '',
				newFlag: true,
				upBtnLoading: false,
				personArr: [],
				messageChange: '改为手动提交',
				submitPact: true,
				shujuShow: false,
				showPerson: false,
				radio: '',
				ensureBtn: false,
				danweiStatus: false,
				shangChuanDis: true,
				alarm: '',
				operationBtn: true, //手动提交按钮 超管
				pidsArr: [],
				addBtnShow: false,
				complieBtnShow: false,
				deleteBtnShow: false,
				readDataShow: false,
				timeStatus: '',
				today: '',
				timeStatusArr: [{
						label: '已过期',
						value: 10
					}, {
						label: '即将过期',
						value: 20
					},
					{
						label: '待保养',
						value: 40
					},
					{
						label: '保养异常',
						value: 50
					},
				]
			}
		},
		computed: {
			//控制搜索结束时间
			timeDisabled() {
				if (this.time_from) {
					return false
				} else {
					return true
				}
			},
			//控制结束时间范围
			pickerOptions() {
				return {
					disabledDate: (time) => {
						return time.getTime() < moment(this.time_from)
					}
				}
			},
			companyId() {
				if (localStorage.company_id) {
					return JSON.parse(localStorage.company_id).id
				} else {
					return ''
				}
			},
			role() {
				if (localStorage.role) {
					return JSON.parse(localStorage.role).id
				} else {
					return ''
				}
			},
			condition() {
				if (this.role == 0) {
					return [{
							value: 10,
							label: "未开始"
						},
						{
							value: 20,
							label: "进行中"
						},
						{
							value: 30,
							label: "维保完成(在线版)"
						},
						{
							value: 40,
							label: "流程结束"
						},
						{
							value: 50,
							label: "离线版完成"
						},
						{
							value: 100,
							label: "打回中"
						},
						{
							value: 60,
							label: "提交市局中"
						},
						{
							value: 80,
							label: "市局成功(物业签字未备案)"
						},
						{
							value: 110,
							label: "首次维保报错"
						},
						{
							value: 120,
							label: "维保查询报错"
						},
						{
							value: 130,
							label: "维保开始报错"
						},
						{
							value: 140,
							label: "维保结束报错"
						},

						{
							value: 90,
							label: "维保确认报错"
						},
					]
				} else {
					return [{
							value: 10,
							label: "未开始"
						},
						{
							value: 20,
							label: "进行中"
						},
						{
							value: 30,
							label: "已完成(物业未确认)"
						},
						{
							value: 40,
							label: "已完成(物业已确认)"
						},
						{
							value: 50,
							label: "已完成(工单未提交)"
						},
						{
							value: 100,
							label: "打回中"
						},
					]
				}
			},
			gongDArr() {
				if (localStorage.baoYang) {
					let arr = JSON.parse(localStorage.baoYang).list
					return arr.filter((item) => {
						return item.name == '保养计划'
					})
				} else {
					return []
				}
			}
		},
		methods: {
			closeVis(){
				this.showVis = false
				if(this.timeStatus || this.attentionStatus || this.attentionStatus === 0){
					this.btnType = 'warning'
				}else{
					this.btnType = 'primary'
				}
			},
			firstMethods() {
				if (localStorage.searchMainPlan) {
					this.attentionStatus = ''
					this.operationBtn = true
					this.submitPact = true
					this.timeStatus = ''
					this.alarm = ''
					this.page = 1
					this.today = ''
					this.page_size_count = 10
					this.query = ''
					this.status = ''
					this.time_from = ''
					this.time_to = ''
					let id = JSON.parse(localStorage.searchMainPlan).id
					if (id == 4) {
						this.timeStatus = 40
					} else if (id == 5) {
						this.timeStatus = 20
					} else if (id == 6) {
						this.timeStatus = 10
					} else if (id == 7) {
						this.timeStatus = 50
					} else if (id == 3) {
						this.today = 1
					}else if(id == 8){
						this.attentionStatus = 1
					}
					localStorage.removeItem('searchMainPlan')
					this.getTableList()
				}
				this.pubLickSearch()
			},
			pubLickSearch(){
				if(this.timeStatus || this.attentionStatus || this.attentionStatus === 0){
					this.btnType = 'warning'
					this.showVis = true
				}else{
					this.btnType = 'primary'
					this.showVis = false
				}
			},
			getPermition() {
				if (this.gongDArr.length != 0) {
					if (this.gongDArr[0].pids) {
						this.pidsArr = this.gongDArr[0].pids
					}
				}
				if (this.pidsArr.length > 0) {
					this.pidsArr.map((item) => {
						if (item.desc == 'get') {
							this.readDataShow = true
						}
						if (item.desc == 'put') {
							this.complieBtnShow = true
						}
						if (item.desc == 'delete') {
							this.deleteBtnShow = true
						}
						if (item.desc == 'post') {
							this.addBtnShow = true
						}
					})
				}
			},
			//手动提交按钮超管
			operationFn() {
				this.$confirm('此操作将手动备案, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let data = {
						task_ids: this.deleteArr.map((item) => {
							return item.id
						})
					}
					axiosPost('/maintain/task/manu/submit/', data, (res) => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '提交成功'
							})
							this.getTableList()
						} else {
							this.$message.error(res.detail.result)
						}
					})
				}).catch(() => {

				});
			},
			//今日故障工单
			publicToday(value) {
				this.page = 1
				this.page_size = 10
				this.loading = true
				this.alarm = value
				this.getTableList()
			},
			jin() {
				this.publicToday(1)
			},
			//昨日
			zuo() {
				this.publicToday(2)
			},
			//其他
			other() {
				this.publicToday(3)
			},
			changeTime() {
				this.time_to = ''
			},
			//打回人员
			reBack() {
				this.showPerson = true
				this.personArr = this.deleteArr[0].persons
			},
			//关闭选择人员弹窗
			ClosePersonAlet() {
				this.showPerson = false
			},
			//选择人员
			ensureClick() {
				this.$confirm('此操作将打回提交数据,人员自行修改, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					if (this.radio) {
						this.ensureBtn = true
						this.ClosePersonAlet()
						console.log(this.deleteArr)
						let tasks = this.deleteArr.map((item) => {
							return item.id
						})
						let data = {
							tasks: tasks,
							person_id: this.radio
						}
						this.loading = true
						noLoadingPost('/maintain/task/pushback/', data, (res) => {
							this.ensureBtn = false
							if (res.code == 0) {
								this.$message({
									type: 'success',
									message: '操作成功!'
								});
								this.getTableList()
							} else {
								this.$message.error(res.detail)
							}
						})
					} else {
						this.$message.error('请指定一个人员')
					}
				}).catch(() => {

				});
			},
			//提交市局
			sumbShiJu() {
				this.$confirm('此操作将工单手动提交到市局, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let taskArr = this.deleteArr.map((item) => {
						return item.id
					})
					let data = {
						task_ids: taskArr
					}
					noLoadingPost('/maintain/task/submit/', data, (res) => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '提交成功'
							})
							this.loading = true
							this.getTableList()
						} else {
							this.$message.error(res.detail)
						}
					})
				}).catch(() => {

				});
			},
			//修改市局提交数据
			modification() {
				this.rowId = this.deleteArr[0].id
				this.shujuShow = true
			},
			//改变提交状态
			changeStatusBtn() {
				let data = {
					company_id: this.companyId, //维保单位id
					auto_submit: !this.messageChangeType
				}
				this.loading = true
				noLoadingPost('/user/submit/', data, (res) => {
					console.log(res)
					this.loading = false
					if (res.code == 0) {
						this.getStatus()
						this.getTableList()
					} else {
						this.$message.error(res.detail.result)
					}
				})
			},
			//获取当前状态是否是自动更新状态
			getStatus() {
				let params = {
					company_type: 100,
					page_size_count: 30
				}
				axiosGet('/user/company/', params, (res) => {
					if (res.code == 0) {
						this.messageChange = res.detail.results[0].auto_submit
						this.messageChangeType = res.detail.results[0].auto_submit
						this.messageChange == true ? this.messageChange = '改为手动提交' : this.messageChange = '改为自动提交'
						this.danweiStatus = res.detail.results[0].submit_display
					}
				})
			},
			timeControl() {
				if (this.time_from > this.time_to && !!this.time_to) {
					this.$message({
						type: 'error',
						message: '开始时间不能大于结束时间!'
					})
					this.loading = false
					return false
				}
				if (!this.time_from && this.time_to) {
					this.$message({
						type: 'error',
						message: '不能只选择结束时间!'
					})
					this.loading = false
					return false
				}
			},
			//获取表格数据
			getTableList() {
				this.pubLickSearch()
				this.showVis = false
				this.loading = true
				this.timeControl()
				if(this.attentionStatus == 2){
					this.attentionStatus = ''
				}
				let params = {
					page: this.page,
					page_size_count: this.page_size,
					key_words: this.query,
					status: this.status,
					order_by: this.order_by,
					time_from: this.time_from == null ? '' : this.time_from,
					time_to: this.time_to == null ? '' : this.time_to,
					alarm: this.alarm,
					time_status: this.timeStatus,
					today: this.today,
					follow:this.attentionStatus
				}
				axiosGet('/maintain/task/', params, (res) => {
					console.log(res)
					this.newFlag = false
					if (res.code == 0) {
						this.total = res.detail.count
						this.tableData = res.detail.results
						this.tableData.map((item) => {
							if (this.role == 0) {
								if (item.status == 10) {
									item.statusName = "未开始"
								} else if (item.status == 20) {
									item.statusName = "进行中"
								} else if (item.status == 30) {
									item.statusName = "维保完成(在线版)"
								} else if (item.status == 40) {
									item.statusName = "流程结束"
								} else if (item.status == 50) {
									item.statusName = "离线版完成"
								} else if (item.status == 60) {
									item.statusName = "提交市局中"
								} else if (item.status == 80) {
									item.statusName = "市局成功(物业签字未备案)"
								} else if (item.status == 90) {
									item.statusName = " 维保确认报错"
								} else if (item.status == 100) {
									item.statusName = "打回中"
								} else if (item.status == 110) {
									item.statusName = "首次维保报错"
								} else if (item.status == 120) {
									item.statusName = "维保查询报错"
								} else if (item.status == 130) {
									item.statusName = "维保开始报错"
								} else if (item.status == 140) {
									item.statusName = "维保结束报错"
								}
							} else {
								if (item.status == 10) {
									item.statusName = "未开始"
								} else if (item.status == 20) {
									item.statusName = "进行中"
								} else if (item.status == 40) {
									item.statusName = "已完成(物业已确认)"
								} else if (item.status == 100) {
									item.statusName = "打回中"
								} else if (item.status == 50) {
									item.statusName = '已完成(工单未提交)'
								} else {
									item.statusName = "已完成(物业未确认)"
								}
							}
							return item
						})
					} else {
						this.$message({
							type: 'error',
							message: res.detail.result
						})
					}
					this.loading = false
				})
			},
			//远程过滤
			sortPub(res, value) {
				console.log(res)
				let newValue = ''
				if (value) {
					newValue = value
				}
				if (res == 'register_code' || res == 'internal_no') {
					this.order_by = newValue + `${'elevator__'+res}`
					this.getTableList()
				} else {
					this.order_by = newValue + res
					this.getTableList()
				}
			},
			sortChange(column, prop, order) {
				if (column.order == 'ascending') {
					this.sortPub(column.prop)
				} else {
					this.sortPub(column.prop, '-')
				}
			},
			//行选中
			rowClick(row, column, event) {
				this.$refs.moviesTable.toggleRowSelection(row)
			},
			//选中多行
			selectChange(res) {
				console.log(res)
				this.deleteArr = res
				if (res.length == 1) {
					this.rowId = res[0].id
					if (res[0].status == 10) {
						this.complieBtn = false
					}
					this.detailBtn = false
					this.batchDisable = true
					this.operationBtn = false
					if (res.status == 50) {
						this.shangChuanDis = false
					}
				} else {
					if (res.length == 0) {
						this.complieBtn = true
						this.detailBtn = true
						this.batchDisable = true
						this.shangChuanDis = true
						this.operationBtn = true
					} else {
						this.complieBtn = true
						this.detailBtn = true
						this.shangChuanDis = true
						if (res.every((item) => {
								return item.status == 10
							})) {
							this.batchDisable = false
						} else {
							this.batchDisable = true
						}
						this.operationBtn = false
					}
				}

				if (res.length != 0) {
					if (res.every((item) => {
							return item.status == 50
						})) {
						this.submitPact = false
					} else {
						this.submitPact = true
					}
				} else {
					this.submitPact = true
				}
			},
			//搜索
			find() {
				this.showVis = false
				this.page = 1
				this.page_size_count = 10
				this.getTableList()
			},
			//重新加载
			reset() {
				this.showVis = false
				this.attentionStatus = ''
				this.operationBtn = true
				this.submitPact = true
				this.timeStatus = ''
				this.alarm = ''
				this.page = 1
				this.today = ''
				this.page_size_count = 10
				this.query = ''
				this.status = ''
				this.time_from = ''
				this.time_to = ''
				this.getTableList()
			},
			//分页器数量变化
			handleSizeChange(currentSize) {
				this.page_size = currentSize
				this.getTableList()
			},
			//分页器页数变化
			handleCurrentChange(currentPage) {
				this.page = currentPage
				this.getTableList()
			},
			//导出
			educe() {
				this.$confirm('此操作将导出全部工单信息, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					loadFn()
					this.timeControl()
					let data = {
						time_from: this.time_from == null ? '' : this.time_from,
						time_to: this.time_to == null ? '' : this.time_to,
						request_type: "task",
					}
					axiosChange('/user/download/', 'post', data, (res) => {
						console.log(res)
						AllLoading.close()
						if (res.code == 0) {
							window.location.href = res.detail
						} else {
							this.$message.error(res.detail.result);
						}
					})
				}).catch(() => {

				});
			},
			//导入
			leadPub() {
				this.upBtnLoading = false
				this.dialogVisible = false
				this.fileList = []
			},
			submit() {
				if (this.fileList.length != 0) {
					const formData = new FormData();
					this.upBtnLoading = true
					formData.append('task', this.fileList[0].raw);
					noLoadingPost('user/upload/', formData, (res) => {
						this.leadPub()
						if (res.code == 0) {
							this.$message({
								type: "success",
								message: '上传成功',
							})
						} else if (res.code != 40500) {
							this.$message({
								type: "error",
								message: "第" + res.detail.line + "行/" + "第" + res.detail.column + "列出错:" + res.detail.msg
							})
						} else {
							this.$message.error(res.detail.result)
						}
					})
				} else {
					this.$message.error("请上传文件!")
				}
			},
			callOff() {
				this.leadPub()
			},
			//查看详情
			lookDetail() {
				this.detailShow = true
			},
			//关闭
			maskShowNow(isShow) {
				this.detailShow = false
				this.shujuShow = false
				console.log(isShow)
				if (isShow == 1) {
					this.getTableList()
				}
			},
			//编辑/添加 关闭
			detailMaskShow(isShow) {
				this.addAndCompileShow = false
				if (isShow == 1) {
					this.getTableList()
				}
			},
			//添加打开弹窗
			addPlan() {
				this.addAndCompileShow = true
				this.isAddOrComp = 1
			},
			//编辑
			compileFn() {
				this.addAndCompileShow = true
				this.isAddOrComp = 2
			},
			//删除
			//单删除
			oneDelete() {
				let url = '/maintain/task/' + this.rowId + '/'
				axiosDelete(url, {}, (res) => {
					console.log(res)
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '删除成功'
						})
						this.getTableList()
					} else {
						this.$message.error(res.detail.result)
					}
				})
			},
			//多删除
			allDelete() {
				let newdeleteArr = this.deleteArr.map(item => {
					return item.id
				})
				let data = {
					task_ids: newdeleteArr
				}
				axiosDelete('/maintain/task', data, (res) => {
					console.log(res)
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '删除成功'
						})
						this.getTableList()
					} else {
						this.$message.error(res.detail.result)
					}
				})
			},
			deleteList(value) {
				this.$confirm('此操作将永久删除工单, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					if (value == 1) {
						this.oneDelete()
					} else {
						this.allDelete()
					}
				}).catch(() => {});
			}
		}
	}
</script>

<style lang="less" scoped>
	.pag {
		margin-top: 10px;
	}

	.Brindcolor {
		color: #409EFF;
	}

	.Redcolor {
		color: #F56C6C;
	}

	.marginTop {
		margin-top: 10px !important;
	}
</style>
